import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:provider/provider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBGongGongCreateTimeModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBWorkTaiNetWork/YBBaseWorkTaiNetWorkManager.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBUtils/YBBaseUtils/YBCallPhoneUtils.dart';

import 'YBMiShuProvider/YBMiShuProvider.dart';
import 'YBMiShuSubPage/YBMiShuTongListDetailSubPage.dart';


class YBYiYiDetailPage extends StatefulWidget {

  final String sysCode;
  final String requestCode;

  const YBYiYiDetailPage({Key key, this.sysCode, this.requestCode}) : super(key: key);

  @override
  _YBYiYiDetailPageState createState() => _YBYiYiDetailPageState(sysCode: sysCode,requestCode: requestCode);
}

class _YBYiYiDetailPageState extends State<YBYiYiDetailPage> {

  final String sysCode;
  final String requestCode;

  _YBYiYiDetailPageState({this.sysCode, this.requestCode});

  bool _selectXieYi = false;



  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text(
            YBChineseText.workTaiShangJiDetailTitle,style: YBTextStyle.TextStyle30313320Medium
          ),
        ),
        body:MultiProvider(
          providers:[
            ChangeNotifierProvider(create:(context)=>YBYIJiTonglvsiTongYouXuanDetailProvider()..getGongGongYouXuanDataList(sysCode, requestCode)),
          ],
          child: Consumer<YBYIJiTonglvsiTongYouXuanDetailProvider>(
              builder:(context,yihuoData,child){
                String createTimeStr;
                if (yihuoData.gongGongYouXuanModel.requestAssignRecordList != null) {
                  YBGongGongCreateTimeModel createTimeModel = yihuoData.gongGongYouXuanModel.requestAssignRecordList.last;
                  createTimeStr = createTimeModel.createTime;
                }

                Widget statusWidget;
                if (yihuoData.gongGongYouXuanModel.status == 0){
                    statusWidget = Text(
                      YBChineseText.workTaiShangJiDaiChuLiTitle,style:YBTextStyle.TextStyleFDB33313,
                    );
                }else if (yihuoData.gongGongYouXuanModel.status == 1){
                  statusWidget = Text(
                    YBChineseText.workTaiYiBaoHuiTitle,style:YBTextStyle.TextStyleFA323213,
                  );
                }else if (yihuoData.gongGongYouXuanModel.status == 2){
                  statusWidget = Text(
                    YBChineseText.workTaiYiTongGuoTitle,style:YBTextStyle.TextStyle47C20013,
                  );
                }else{
                  statusWidget = Text(
                    ''
                  );
                }

                return Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    Expanded(
                      child:CustomScrollView(
                        slivers: <Widget>[
                          SliverToBoxAdapter(
                            child: Container(
                              child: Column(
                                children: [
                                  Container(
                                    color:YBColor.white,
                                    child: Padding(
                                      padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                      child: Column(
                                        children: [
                                          Container(
                                            height: YBTextStyle.adapterSize20,
                                          ),
                                          Container(
                                            child: Row(
                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                              crossAxisAlignment: CrossAxisAlignment.center,
                                              children: [
                                                Container(
                                                  child: Text(
                                                    createTimeStr??"",
                                                    style: YBTextStyle.TextStyle1B1C1F15Medium,
                                                  ),
                                                ),
                                                Container(
                                                  child: Text(
                                                    "${yihuoData.gongGongYouXuanModel.request.provinceName}-${yihuoData.gongGongYouXuanModel.request.cityName}"??"",
                                                    style: YBTextStyle.TextStyle6E737A13,
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                          Container(
                                            height: YBTextStyle.adapterSize16,
                                          ),
                                          Container(
                                            child: Row(
                                              children: [
                                                Container(
                                                  child: Image.asset(YBImageStyle.getImagePath('BLBBusinessOppoManager_phonr')),
                                                ),
                                                Container(
                                                  width: YBTextStyle.adapterSize5,
                                                ),
                                                Container(
                                                  child: Text(
                                                    yihuoData.gongGongYouXuanModel.linkPhone??'',
                                                    style: YBTextStyle.TextStyle6E737A13,
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                          Container(
                                            height: YBTextStyle.adapterSize16,
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                  Container(
                                    height: YBTextStyle.adapterSize8,
                                  ),
                                  Container(
                                    color: YBColor.white,
                                    child: Padding(
                                      padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                      child: Column(
                                        mainAxisAlignment: MainAxisAlignment.start,
                                        crossAxisAlignment: CrossAxisAlignment.stretch,
                                        children: [
                                          Container(
                                            child: Text(
                                              YBChineseText.workTaiXuQiuNeiRongTitle,
                                              style: YBTextStyle.TextStyle1B1C1F15Medium,
                                            ),
                                          ),
                                          Container(
                                            height: YBTextStyle.adapterSize15,
                                          ),
                                          Container(
                                            child: Text(
                                              yihuoData.gongGongYouXuanModel.request.requestServiceDesc??"",
                                              style: YBTextStyle.TextStyle6E737A13,
                                            ),
                                          ),
                                          Container(
                                            height: YBTextStyle.adapterSize15,
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                  Container(
                                    height: YBTextStyle.adapterSize8,
                                  ),
                                ],
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              color:YBColor.white,
                              child: Padding(
                                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize15),
                                child: Text(
                                  YBChineseText.workTaiMishuDetailliuzhuanJiluTitle,
                                  style: YBTextStyle.TextStyle1B1C1F15Medium,
                                ),
                              ),
                            ),
                          ),
                          SliverList(
                            delegate:SliverChildBuilderDelegate((_,int index){
                              YBGongGongCreateTimeModel createTimeModel = yihuoData.gongGongYouXuanModel.requestAssignRecordList[index];
                              return YBMiShuTongListDetailSubPage(numberStr: (index + 1).toString(),timeStr: createTimeModel.createTime,);
                            },
                                childCount: yihuoData.gongGongYouXuanModel.requestAssignRecordList.length
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              height: YBTextStyle.adapterSize44,
                              color: YBColor.white,
                              child: Padding(
                                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                child: Row(
                                  children: [
                                    Container(
                                      child: Text(YBChineseText.workTaiYiYiZhuangTaiTitle,style: YBTextStyle.TextStyle18181814Medium,),
                                    ),
                                    Container(
                                      child:statusWidget,
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                    Container(
                      child: Padding(
                        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Container(
                              child:InkWell(
                                child: _selectXieYi == false?Image.asset(YBImageStyle.getImagePath("login_default")):Image.asset(YBImageStyle.getImagePath("login_selected")),
                                onTap: () async {
                                  setState(() {
                                    _selectXieYi = !_selectXieYi;
                                  });
                                },
                              ),
                            ),
                            Container(
                              width: YBTextStyle.adapterSize5,
                            ),
                            Container(
                              child: RichText(
                                text:TextSpan(
                                  style: YBTextStyle.homeSmallSubText,
                                  children:<InlineSpan>[
                                    TextSpan(
                                      text: YBChineseText.woYiYueDuBingTongYiTitle,
                                      style: YBTextStyle.logincolor383A3D13Light,
                                    ),
                                    TextSpan(
                                        text: YBChineseText.workTaiShangJiKuManangerTitle,
                                        style: YBTextStyle.login2D69E013light,
                                        recognizer: TapGestureRecognizer()..onTap = (){
                                          if (sysCode.contains('xg_newyijiwang')) {
                                            YBApplication.router.navigateTo(context,
                                                "/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage/workTaiMiShuShangJiManangerIdeaYiJiPage");
                                          }else if (sysCode.contains("xg_jinrilvsi")){
                                            YBApplication.router.navigateTo(context,
                                                "/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage/workTaiMiShuShangJiManangerIdeaLvSiPage");
                                          }
                                        }
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Container(
                      height: YBTextStyle.adapterSize15,
                    ),
                    Container(
                      height: YBTextStyle.adapterSize44,
                      child: Padding(
                        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                        child:Row(
                          children: [
                            Container(
                              child: InkWell(
                                child: Column(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Container(
                                      child: Image.asset(YBImageStyle.getImagePath('lawyer_telphone'),width: YBTextStyle.adapterSize20,height: YBTextStyle.adapterSize20,),
                                    ),
                                    Container(
                                      child: Text(YBChineseText.workTaiDianHuaTitle,style: YBTextStyle.TextStyle7A7A7A011,),
                                    ),
                                  ],
                                ),
                                onTap: () async {
                                  YBCallPhoneUtils().getCallPhoneUtils(yihuoData.gongGongYouXuanModel.linkPhone??"");
                                },
                              ),
                            ),
                            Container(
                              child: Row(
                                children: [
                                  Container(
                                    width: YBTextStyle.adapterSize10,
                                  ),
                                  Container(
                                    child: InkWell(
                                      child: Column(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: [
                                          Container(
                                            child: Image.asset(YBImageStyle.getImagePath('mine_mybangzhu'),width: YBTextStyle.adapterSize20,height: YBTextStyle.adapterSize20,),
                                          ),
                                          Container(
                                            child: Text(YBChineseText.workTaiYiYiTitle,style: YBTextStyle.TextStyle7A7A7A011,),
                                          ),
                                        ],
                                      ),
                                      onTap: () async {

                                      },
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            Container(
                              width: YBTextStyle.adapterSize10,
                            ),
                            Expanded(
                              child:MaterialButton(
                                  shape: RoundedRectangleBorder(
                                    side: BorderSide.none,
                                    borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize8)),
                                  ),
                                  color: YBColor.commonThemeColor,
                                  child: Text(YBChineseText.workTaiXiuGaiFanKuiTitle,style: YBTextStyle.xieGangQingNianTuiGuangYuanBtnText,),
                                  onPressed:(){
                                    if(_selectXieYi == false){
                                      EasyLoading.showInfo(YBChineseText.qingTongYiXieYiTitle);
                                      return;
                                    }
                                    _youXiaoShangJi(requestCode, sysCode);
                                  }),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Container(
                      height: YBTextStyle.adapterSize15,
                    ),
                  ],
                );
              }
          ),
        ),
      ),
    );
  }
  void _youXiaoShangJi(String requestCode, String sysCode){
    print('-----$requestCode---$sysCode-');
    YBBaseWorkTaiNetWork.workTaiYiHuoShangJiYouXiao({
      "requestCode":requestCode,
      "sysCode":sysCode,
    },success: (data){
      print('object--$data');
    },fail: (error){
      print('object--$error');
    });
  }
}


